// ==UserScript==
// @name         123网盘重定向
// @version      0.3
// @description  将123网盘请求重定向到123684.com域名，同时排除分享链接
// @author       DeepSeek
// @match        *://www.123pan.com/*
// @match        *://123pan.com/*
// @match        *://www.123684.com/*
// @match        *://www.123912.com/*
// @match        *://www.123865.com/*
// @match        *://www.123952.com/*
// @icon         https://login.123pan.com/static/favicon.ico
// @run-at       document-start
// @grant        none
// @updateURL    https://gitee.com/selling-surprises/Greasyfork-Script-repository/raw/main/%E7%BD%91%E7%9B%98/123%E7%BD%91%E7%9B%98/123%E7%BD%91%E7%9B%98%E9%87%8D%E5%AE%9A%E5%90%91.user.js
// ==/UserScript==

(function() {
    'use strict';
    
    const TARGET_DOMAIN = '123684.com';
    const REDIRECT_DOMAINS = [
        '123pan.com',
        '123865.com',
        '123952.com',
        '123912.com'
    ];
    
    const currentHost = window.location.hostname;
    const baseDomain = currentHost.replace(/^www\./i, '').split('.').slice(-2).join('.');
    const currentPath = window.location.pathname;
    
    // 检查是否是分享链接（路径中包含 /s/）
    const isShareLink = /^\/s\//.test(currentPath);
    
    // 检查是否需要重定向（排除分享链接）
    if (REDIRECT_DOMAINS.includes(baseDomain) && !isShareLink) {
        const url = new URL(window.location.href);
        const newHost = currentHost.startsWith('www.') 
            ? `www.${TARGET_DOMAIN}` 
            : TARGET_DOMAIN;
        
        // 避免循环重定向
        if (url.hostname !== newHost) {
            url.hostname = newHost;
            window.location.replace(url.href);
        }
    }
})();